/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "sle_seek_hdi.h"
#include "sle_hal_errcode.h"
#include "sle_hilog.h"
#include "sle_device_discovery.h"
#include "sle_common.h"
#include "sle_callback_adapter.h"

SleHdiErrorCode SleHdiAdapterStartSeekHdi(void)
{
    SleHdiErrorCode ret = SLE_HDI_ERRCODE_FAIL;
    ret = (SleHdiErrorCode)sle_start_seek();
    return ret;
}

SleHdiErrorCode SleHdiAdapterStopSeekHdi(void)
{
    SleHdiErrorCode ret = SLE_HDI_ERRCODE_FAIL;
    ret = (SleHdiErrorCode)sle_stop_seek();
    return ret;
}

SleHdiErrorCode SleHdiAdapterSetSeekParamHdi(const SleSeekParam *param)
{
    SLE_ASSERT_AND_RETURN_RET_LOG(param != NULL, SLE_HDI_ERRCODE_FAIL, "SetSeekParamHdi");
    SleHdiErrorCode ret = SLE_HDI_ERRCODE_FAIL;
    sle_seek_param_t param_sdk = {
        .own_addr_type = (uint8_t)param->addrType,
        .filter_duplicates = (uint8_t)param->repateFilter,
        .seek_filter_policy = (uint8_t)param->filterPolicy,
        .seek_phys = (uint8_t)param->phys,
    };
    memcpy(param_sdk.seek_type, param->type, sizeof(param_sdk.seek_type));
    memcpy(param_sdk.seek_interval, param->interval, sizeof(param_sdk.seek_interval));
    memcpy(param_sdk.seek_window, param->window, sizeof(param_sdk.seek_window));
    ret = (SleHdiErrorCode)sle_set_seek_param(&param_sdk);
    return ret;
}

SleHdiErrorCode SleHdiAdapterRegisterSeeCbksHdi(SleSeekHdiCallbacks *callbacks)
{
    SLE_ASSERT_AND_RETURN_RET_LOG(callbacks != NULL, SLE_HDI_ERRCODE_INVALID_PARAM, "RegisterSeeCbksHdi");
    SleHdiErrorCode ret = SLE_HDI_ERRCODE_FAIL;
    ret = RegisterSeekCallbackAdapter(callbacks);
    return ret;
}

SleHdiErrorCode GetSleSeekHdiOpts(SleSeekHdiOpts *seekOpts)
{
    SLE_ASSERT_AND_RETURN_RET_LOG(seekOpts != NULL, SLE_HDI_ERRCODE_INVALID_PARAM, "GetSleSeekHdiOpts");
    seekOpts->startSeek = SleHdiAdapterStartSeekHdi;
    seekOpts->stopSeek = SleHdiAdapterStopSeekHdi;
    seekOpts->setSeekParam = SleHdiAdapterSetSeekParamHdi;
    seekOpts->registerSeeCbks = SleHdiAdapterRegisterSeeCbksHdi;
    return SLE_HDI_ERRCODE_SUCC;
}